
/************************************************************/
//文件名：main
//功能:测试linux下key驱动以及led驱动测试
//使用说明: (1) 采用系统调用方式
//          (2)
//          (3)
//          (4)
//作者:彭文正
//日期:2020-8-30

/************************************************************/
#include <linux/input.h>                                                                                                                                                                                     
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>

#define INPUT_DEV "/dev/input/by-path/platform-joystick-event"
#define MOTER_DEV "/sys/devices/platform/led/leds/moter/brightness"

int main(int argc, char * const argv[])
{
    int fd = 0; int moter_fd =0;
    struct input_event event;
    int ret = 0;
    fd = open(INPUT_DEV, O_RDONLY);
    moter_fd = open(MOTER_DEV, O_WRONLY);


	if((fd <= 0)||(moter_fd <=0) )
	{
		perror("open err\r\n");
		exit(1);
	}
    while(1){
        ret = read(fd, &event, sizeof(event));
	    if(ret == -1) {
            perror("Failed to read.\n");
            exit(1);
        }
        if(event.type != EV_SYN) 
		{
            printf("type:%d, code:%d, value:%d\n", event.type, event.code, event.value);
             if (event.code == 59) write(moter_fd, "1", 1);
             if (event.code == 60) write(moter_fd, "0", 1); 
        }
    }   
    return 0;
}